/**
 * Copyright (C) 2009 Bruno Dumas (bruno.dumas -at- unifr.ch), DIVA group, University of Fribourg, Switzerland
 * 
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 */

//SMUIML v0.4

package it.unina.lab.smuil;

import it.unina.lab.costants.Constants;
import it.unina.lab.xml.Attribute;
import it.unina.lab.xml.HephaisTKParsingException;
import it.unina.lab.xml.XmlGeneric;

import java.util.Vector;


public class Recognizers extends Smuiml_Generic {
	/**
	 *
	 */
	private static final long serialVersionUID = 2937587285373952302L;

	public final static String NAME = "recognizers";

	private Vector<Recognizer> recognizers = null;

	public Recognizers(){
		super();
		setName(NAME);
		recognizers = new Vector<Recognizer>();
	}

	public Vector<Recognizer> getRecognizers(){
		return recognizers;
	}

	public Recognizer getRecognizer(int index){
		return recognizers.get(index);
	}

	public int recognizersSize(){
		return recognizers.size();
	}

	public void addRecognizer(Recognizer recognizer){
		recognizers.add(recognizer);
		elements.add(recognizer);
	}

	public void addElement(XmlGeneric element) throws HephaisTKParsingException {
		if(element instanceof Recognizer){
			this.addRecognizer((Recognizer)element);
		}else{
			throw new HephaisTKParsingException(getNamespace()+"."+NAME+" -- unexpected element: "+element.getName());
		}
	}

	@Override
	public void addAttribute(Attribute attribute) throws HephaisTKParsingException{
		super.addAttribute(attribute);
		String attName = attribute.getName();
		if (attName.indexOf(':') != -1) {
			attName = attName.substring(attName.indexOf(':')+1);
		}
		addAttribute(attName, attribute.getValue());
	}

	public void addAttribute(String name, String value) throws HephaisTKParsingException{
		throw new HephaisTKParsingException(getNamespace()+"."+NAME+" -- unexpected attribute: "+name);
	}

	public String toString(int indent) {
		StringBuilder ret = new StringBuilder();
		for(int i = 0; i < indent; i++){
			ret.append(' ');
		}
		ret.append("<"+NAME+">\n");
		for (int i = 0; i < recognizers.size(); i++){
			ret.append(recognizers.get(i).toString(indent + Constants.INDENT_PREFIX));
		}
		for(int i = 0; i < indent; i++){
			ret.append(' ');
		}
		ret.append("</"+NAME+">\n");
		return ret.toString();
	}
}
